package com.example.win.android_banduyujia.http.request;

import android.os.Handler;
import android.os.Message;

import com.example.win.android_banduyujia.http.HttpUtils;
import com.example.win.android_banduyujia.http.UrlContext;
import com.example.win.android_banduyujia.http.response.BaseHttpResponse;
import com.example.win.android_banduyujia.http.response.ResponseError;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseActivity;

import org.json.JSONObject;

import java.util.Map;

/**
 * Created by Win on 2015/10/12.
 */
public class UpdaloadRequest extends BaseHttpRequest  {
    private String mUrl = UrlContext.Url_UPLOAD.getContext();

    private  String mAccessToken = null;

    public void doRequestFile(BaseActivity context,
                                     final Class<? extends BaseHttpResponse> clzz, final Handler callbackHandler,
                                     final boolean isShowProgressDialog, final Handler pHandler, String file) {
      if(isShowProgressDialog){
          pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_START);
      }
        Message message=new Message();
        JSONObject result;
        BaseHttpResponse response=null;
        ResponseError  error = new ResponseError();

        try{
            HttpUtils.uploadImage(toRequestURL(), getHttpHeader(), getHttpParams(), "avatar", "avatar", file);
            pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_END);
        }catch (Exception e){
            e.printStackTrace();
            error.setMessage("Client exception");
            pHandler.sendEmptyMessage(AsycHttpRequest.CODE_TASK_END);
        }
    }

    public UpdaloadRequest(String access_token) {
         mAccessToken = access_token;
    }

    @Override
    protected String toHttpMethod() {
        return HTTP_METHOD_POST;
    }

    @Override
    protected String toRequestURL() {
        return String.format(mUrl, mAccessToken);
    }

    @Override
    protected void toHttpRequestParams(Map<String, String> params) {
      //  params.put("access_token", mAccessToken);
        params.put("pic_type", "1");
        params.put("pic_type", "2");
        params.put("pic_type", "3");
        params.put("pic_type", "4" );
    }
}
